<script>
import {createOrder} from "@/api/order";

export default {
  name: "RegistrationConfirmation",
  data(){
    return{
      appointmentItem:{doctor:{user:{},department:{}}},
      appointmentTimeItem: {},
      weekDay:null,
      dialogVisible:false,
      user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {},
      order:{
        patientId:localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")).patientId : null,
        appointmentSchedulerId:null,
        appointmentTime:null,
        type:'0',
        amount:null
      }
    }
  },
  created() {
    let appointmentInfo=JSON.parse(decodeURIComponent(this.$route.query.appointmentInfo));
    this.appointmentItem=appointmentInfo.appointmentItem;
    this.appointmentTimeItem=appointmentInfo.appointmentTimeItem;
    this.weekDay=this.getWeekDay(this.appointmentItem.workDate);
  },
  methods:{
    confirm(){
      this.dialogVisible=false;
      this.order.appointmentSchedulerId=this.appointmentItem.id;
      this.order.appointmentTime=this.appointmentTimeItem.appointmentTime;
      this.order.amount=this.appointmentItem.doctor.registrationFee;
      createOrder(this.order).then(res=>{
        if(res.code === 200){
          this.$message({
            message: '挂号订单已生成，请在10分钟内完成支付',
            type: 'success',
            center: true
          })
          this.$router.push("/front/registrationOrder");
        }
      });

    },
    getWeekDay(date){
      let weekDays=['星期日','星期一','星期二','星期三','星期四','星期五','星期六']
      return weekDays[new Date(date).getDay()];
    }
  }
}
</script>

<template>
<div>
  <el-descriptions  :column="1" :size="'medium'" style="margin-bottom: 30px">
    <template slot="title">
     <i class="el-icon-paperclip" style="color: #3a8ee6"></i><span style="margin-left: 5px">挂号信息</span>
    </template>
    <el-descriptions-item label="就诊时间"><span style="font-weight: bold">{{appointmentItem.workDate}}({{weekDay}})&ensp;{{appointmentTimeItem.appointmentTime}}-{{appointmentTimeItem.finishTime}}&ensp;{{appointmentItem.dayPart=='0'?'上午':'下午'}}</span></el-descriptions-item>
    <el-descriptions-item label="就诊科室"><span style="font-weight: bold">{{appointmentItem.doctor.department.name}}</span></el-descriptions-item>
    <el-descriptions-item label="医生姓名"><span style="font-weight: bold">{{appointmentItem.doctor.user.userName}}</span></el-descriptions-item>
    <el-descriptions-item label="医生职称"><span style="font-weight: bold">{{appointmentItem.doctor.position}}</span></el-descriptions-item>
    <el-descriptions-item label="医生专长"><span style="font-weight: bold">{{appointmentItem.doctor.characteristics}}</span></el-descriptions-item>
    <el-descriptions-item label="挂号费用"><span style="font-weight: bold">{{appointmentItem.doctor.registrationFee}}元</span></el-descriptions-item>
  </el-descriptions>
  <el-descriptions  :column="1" :size="'medium'">
    <template slot="title">
      <i class="el-icon-user" style="color: #3a8ee6"></i><span style="margin-left: 5px">用户信息</span>
    </template>
    <el-descriptions-item label="用户姓名"><span style="font-weight: bold">{{user.userName}}</span></el-descriptions-item>
    <el-descriptions-item label="用户性别"><span style="font-weight: bold">{{user.sex=='0'?'男':'女'}}</span></el-descriptions-item>
    <el-descriptions-item label="用户身份证号"><span style="font-weight: bold">{{user.idNumber}}</span></el-descriptions-item>
    <el-descriptions-item label="用户电话"><span style="font-weight: bold">{{user.phonenumber}}</span></el-descriptions-item>
    <el-descriptions-item label="用户邮箱地址"><span style="font-weight: bold">{{user.email}}</span></el-descriptions-item>
  </el-descriptions>
  <div style="text-align: center;margin-top: 50px"><el-button type="primary" size="medium" @click="dialogVisible=true">确认挂号</el-button><el-button  @click="$router.push('/front/scheduler')" size="medium" plain>重新选择</el-button></div>
  <el-dialog
      title="重要提示"
      :visible.sync="dialogVisible"
      width="30%">
    <span style="color: red;font-size: 20px">请使用本人真实信息预约，根据需要，平台将会进行电话回访。若不能联系您，有权强制取消您的预约并纳入黑名单。谢谢合作。
用户预约成功，未按时取号就诊累计达3次（含3次，医院停诊与提前取消预约除外）将纳入黑名单，黑名单用户6个月内无法预约挂号！</span>
    <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="confirm()">确 定</el-button>
  </span>
  </el-dialog>
</div>
</template>

<style scoped>
</style>